A potentiometer is a variable resistor that can adjust a voltage from 0V to the maximum circuit voltage. By taking a reading of this voltage we can control other things, like volume, light, movement, etc. The reading is analogue, in that it can vary continuously between the minimum and maximum.
Wire up the potentiometer like this:
Circuit | Pico |
---|---|
Black | GND |
Red | 3V3 |
Green | GP28 or another analogue pin |
Write this code and download to the Pico.
See code on github# Test Potentiometer
import time
import board
import analogio
# Set up the potentiometer on pin 28 as an analogue input pin
pot = analogio.AnalogIn(board.GP28_A2)
# Value will be 0 to 65535 (direction of increase/decrease depending on the order of black/red wires)
while True:
val = pot.value
print(val)
time.sleep(.2)
Turn the knob on the potentiometer. The values printed out should change.